package com.ocelot.san.service;

import java.io.Serializable;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import com.ocelot.san.dto.Client;
import com.ocelot.san.repository.ClientRepository;

@Service
public class ClientService implements Serializable {

	private static final long serialVersionUID = 8396906661593149258L;

	@Resource
	private ClientRepository clientRepository;

	public void save(Client client) {
		clientRepository.save(client);
	}

	public Client findById(Long id) {
		return clientRepository.findOne(id);
	}

	public void delete(Long id) {
		clientRepository.delete(id);
	}

	public List<Client> findAll() {
		return clientRepository.findAll(sortByNameAsc());
	}

	private Sort sortByNameAsc() {
		return new Sort(Sort.Direction.ASC, "name");
	}

}
